package com.imooc.api;

import com.imooc.api.intercept.JWTCurrentUserInterceptor;
import com.imooc.api.intercept.SMSInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class interceptConfig implements WebMvcConfigurer {

    /***
     * springboot中放入拦截器
     * @return
     */
    @Bean
    public SMSInterceptor smsInterceptor(){
        return new SMSInterceptor();
    }


    @Bean
    public JWTCurrentUserInterceptor jwtCurrentUserInterceptor() {
        return new JWTCurrentUserInterceptor();
    }


    /***
     * 注册拦截器，拦截指定的路由
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(smsInterceptor()).addPathPatterns()
                .addPathPatterns("/passport/getSMSCode");

        registry.addInterceptor(jwtCurrentUserInterceptor())
                .addPathPatterns("/**");
    }
}
